import {
  createBrowserRouter,
  Navigate
} from 'react-router-dom'
import { lazy } from 'react'

const Layout = lazy(() => import('@/layouts/index.jsx'))
const SalesManage = lazy(() => import('@/pages/salesManage/index.jsx'))
const PurchaseManage = lazy(() => import('@/pages/purchaseManage/index.jsx'))
const WarehouseManage = lazy(() => import('@/pages/warehouseManage/index.jsx'))
const FinanceManage = lazy(() => import('@/pages/financeManage/index.jsx'))
const AccountsManage = lazy(() => import('@/pages/accountsManage/index.jsx'))
const Department = lazy(() => import('@/pages/basicData/department/index.jsx'))
const Product = lazy(() => import('@/pages/basicData/product/index.jsx'))
const Supplier = lazy(() => import('@/pages/basicData/supplier/index.jsx'))
const Dashboard = lazy(() => import('@/pages/dashboard/index.jsx'))
const Login = lazy(() => import('@/pages/login/index.jsx'))

export const routerArr = [
  {
    path: '/',
    element: <Navigate to='/login' replace />,
  },
  {
    element: <Layout />,
    children: [
      {
        // 首页
        path: '/dashboard',
        element: <Dashboard />,
        meta: {
          title: '首页',
          key: 'dashboard'
        }
      },
      {
        // 销售管理
        path: '/salesManage',
        element: <SalesManage />,
        meta: {
          title: '销售管理',
          key: 'salesManage'
        }
      },
      {
        // 采购管理
        path: '/purchaseManage',
        element: <PurchaseManage />,
        meta: {
          title: '采购管理',
          key: 'purchaseManage'
        }
      },
      {
        // 库存管理
        path: '/warehouseManage',
        element: <WarehouseManage />,
        meta: {
          title: '库存管理',
          key: 'warehouseManage'
        }
      },
      {
        // 财务管理
        path: '/financeManage',
        element: <FinanceManage />,
        meta: {
          title: '财务管理',
          key: 'financeManage'
        }
      },
      {
        // 账务管理
        path: '/accountsManage',
        element: <AccountsManage />,
        meta: {
          title: '账务管理',
          key: 'accountsManage'
        }
      },
      {
        // 部门
        path: '/department',
        element: <Department />,
        meta: {
          title: '部门管理',
          key: 'department'
        }
      },
      {
        // 产品
        path: '/product',
        element: <Product />,
        meta: {
          title: '产品管理',
          key: 'product'
        }
      },
      {
        // 供应商
        path: '/supplier',
        element: <Supplier />,
        meta: {
          title: '供应商管理',
          key: 'supplier'
        }
      }
    ]
  },
  {
    path: '/login',
    element: <Login />
  }
]
const router = createBrowserRouter(routerArr)

export default router
